/**
 * 用于 瀑布流 模块
 */
const Pager = require('../../components/aotoo/core/index')
const lib = Pager.lib

const adapter = (data) => {
  return data.map(item => {
    return {
      img: {
        src: item.img,
        mode: item.mode || 'widthFix',
      },
      title: item.title,
      aim: 'onJumpOther?id='+item.id
    }
  })
}

module.exports = function(params={}) {
  let dft = {}
  let opts = Object.assign({}, dft, params)
  let $id = opts.$$id || 'waterfallx'
  return {
    $$id: $id,
    containerId: opts.containerId,
    scrollCfg: {
      scroll: true,    //
      'scroll-y': opts.scrollCfg['scroll-y'] || opts.scrollCfg['scroll-y'] === true ? true : false,
      'lower-threshold': opts.scrollCfg['lower-threshold'] || 0,                              //上或左
      'upper-threshold': opts.scrollCfg['upper-threshold'] || 100,                              //下或或
      bindscrolltolower: opts.scrollCfg['bindscrolltolower'] || 'bindscrolltolower',            //下或或
      // bindscrolltoupper: opts.scrollCfg['bindscrolltoupper'] || 'bindscrolltoupper',            //上或左
      // 'enable-back-to-top': opts.scrollCfg['enable-back-to-top'] || opts.scrollCfg['enable-back-to-top'] === true ? true : false
    },
    listClass: opts.listClass,
    itemClass: opts.itemClass,
    data: adapter(opts.data),
    itemMethod: {
      
    },
    methods: {
      __ready() {
        const that = this
        this.hooks.once('sysScroll', (params)=> {
          const data = params.data
          if (data && data.length > 0) {
            this.insertx(adapter(data))
          }
          else {
            this.loaded()
          }
        })
        this.isloaded = false
        this.hooks.once('loadingData', function() {
          if (!that.isloaded) {
            that.insertx(adapter(opts.data))
            that.isloaded = true
          }
          else {
            that.loaded()
          }
        })
      }
    }
  }
}
